package com.comleader.ldmapdownload.util;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author ：杨浩毅 (1759)
 * @date ：2020/9/10 11:41
 */
public class TimeUtils {
    public static String getGapTime(long time) {
        long hours = time / (1000 * 60 * 60);
        long minutes = (time - hours * (1000 * 60 * 60)) / (1000 * 60);
        String diffTime = "";
        if (hours >= 1) {
            diffTime = hours + "小时" + minutes + "分";
        } else {
            diffTime = minutes + "分";
        }
        return diffTime;
    }


    /**
     * @description 时间戳转换为ui'n
     * @author zhanghang
     * @date 2020-09-25 13:41:01
	 * @param time
     * @return
     **/
    public static String timeStampToString(long time){
        if (time == 0){
            return "";
        }
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String timeStr = sdf.format(new Date(time));
        return timeStr;
    }

    /**
     * @param time
     * @return
     * @description 间隔时间毫秒转换为时长
     * @author zhanghang
     * @date 2020-09-25 12:59:27
     **/
    public static String toDuration(long time) {
        int day = (int) (time / (1000 * 60 * 60 * 24));
        int hours = (int) ((time % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
        int minutes = (int) ((time % (1000 * 60 * 60)) / (1000 * 60));
        int seconds = (int) ((time % (1000 * 60)) / 1000);
        StringBuilder duraTime = new StringBuilder();
        if (day > 0) {
            duraTime.append(day + "天");
        }
        if (hours > 0) {
            duraTime.append(hours + "时");
        }
        if (minutes > 0) {
            duraTime.append(minutes + "分");
        }
        duraTime.append(seconds + "秒");
        return duraTime.toString();
    }
}
